package mysql;


import Alert.ST_name;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author TOMMYNATO
 */
public class connectServer {
 public Connection con = null;public  ResultSet rs = null;public   java.sql.Statement stmt = null; 
    public connectServer(String db){ 
        try {
            Class.forName("com.mysql.jdbc.Driver");
        
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/"+db+"", "root","root"); 
              
         stmt = con.createStatement(); 
            
                //  String sql = "select * from stock_news"; 
    // System.out.println(sql); 
    // rs = stmt.executeQuery(sql); 
    /// rs.next(); 
    // System.out.println(rs.getString(1)+rs.getString(2)+rs.getString(3)+rs.getString(4));
        } catch (SQLException | ClassNotFoundException ex) {
        }
    }
    
        public void CloseDB(){
        try {
            con.close();
            stmt.close();
            //rs.close();
         //   System.out.println("DB CLOSE");
        } catch (SQLException ex) {
        }
        }
    public static void main(String[]args) throws SQLException{
       
        ST_name SN=new ST_name();
        for(int i=0;i<ST_name.st.length;i++){
           connectServer connect = new connectServer("stock_server");
      String sql = "INSERT INTO `stock_data`.`stock_symbol` (`Sname` ,`SType` )VALUES ('kljkjh', '1');"; 
     System.out.println(sql); 
    int a= connect.stmt.executeUpdate(sql); 
    System.out.println(i+"->"+a);
        connect.CloseDB();
    }
    }
    public String DateConver(String date) throws ParseException{
           String d = date; 
              DateFormat df1 = new SimpleDateFormat("dd/MM/yyyy HH:MM",Locale.ENGLISH); 
                DateFormat df2 = new SimpleDateFormat("dd:MM:yy HH:MM",Locale.ENGLISH); 
               // DateFormat df3 = new SimpleDateFormat("EEEE",Locale.US); 
                try { 
                        System.out.println(df2.format(df1.parse(d))); 
                       // System.out.println(df3.format(df1.parse(d))); 
                } catch (ParseException ex) { 
                        ex.printStackTrace(); 
                }
                return df2.format(df1.parse(d));
    }
    
   public void check(){
       
   }
}
